// scaup - Scala up!
// (c) 2008-2009, Normen Müller, normen.mueller@gmail.com  
// $Id: DEP.scala 2480 2009-10-07 11:47:13Z nmueller $
package locutor.model.parsing.dep

import java.io.File
import java.text.MessageFormat.{format}

import scaup.Views._

import locutor.model.G

/** 
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.2 */
case class DepError(message: String) extends Exception(message)

/** This object provides a simple interface to the DEP parser class.
 * 
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.2 */
object DEP extends Parser {
  def apply(input: File): G =
    if(input == null || !(input exists))
      throw new DepError(format("Physical DEP file may not be null (''{0}'').", input))
    else apply(input.content)
  
  def apply(input: String) =
    if(input == null)
      throw new DepError("Physical DEP representation may not be null.")
    else parse(input)
  
  def parse(input: String) = phrase(dep)(new lexical.Scanner(input)) match {
    case Success(result, _) => result
    case n@_                => throw new DepError(format("DEP parsing error in ''{0} ...}''\n", input.lines.next) + n)
  }
}
